#!/usr/bin/env python3
# coding: utf-8

import multiprocessing as MP
import time, logging, sys, os, re, random


class Werk(MP.Process):
    """
    Classed workerk
    """

    def __init__(self, string):
        MP.Process.__init__(self)
        self.string = string

    def run(self):
        print('Sup. I\'m {0}'.format(self), end='')
        if self.string:
            print(' and I have something to show you: "{0}"'.format(self.string), end='')
        print('.')


def func(arg=None):
    print("im'a \"{}\":".format(MP.current_process().name), end=' ')
    if arg is None:
        print("i'ma fish {}".format(time.time()))
    else:
        if arg > 6:
            time.sleep(1.1)
        print('arg = {}'.format(arg))


if __name__ == "__main__" and 0:
    jobs = []
    for i in range(10):
        p = MP.Process(target=func,
                       args=(i if i & 1 else None,),
                       name='wilson' if i in (3, 8) else None)
        print('p = {}'.format(p))
        jobs.append(p)
        p.start()
        print('just started process {} (p={})'.format(p.pid, p))
        print('=' * 79)

if __name__ == "__main__":
    MP.log_to_stderr(logging.DEBUG)

    jobs = [None] * 10
    for i in range(len(jobs)):
        jobs[i] = Werk(None if random.randint(0, 1)
                            else random.choice(''.join([chr(c) for c in
                                                        range(ord('A'), ord('Z') + 1)])))

    for j in jobs:
        print(j)

    for j in jobs:
        j.start()

    for j in jobs:
        j.join()
